package com.leo.springbootmultithreadbasic.threadpool;

import com.leo.springbootmultithreadbasic.common.CommonConstant;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;


public class ThreadPoolConfig {

    /**
     * 线程池的阻塞队列:
     * LinkedBlockingQueue、SynchronousQueue、ArrayBlockingQueue、LinkedTransferQueue、PriorityBlockingQueue
     */
    private LinkedBlockingQueue<Runnable> linkedBlockingQueue = new LinkedBlockingQueue<>(2);

    /**
     * Thread factory
     */
    private ThreadFactory threadFactory = new MyThreadFactory2("ThreadFactory");

    public ThreadPoolExecutor threadPoolExecutor =
            new ThreadPoolExecutor(CommonConstant.CORE_POOL_SIZE,
                                   CommonConstant.MAXIMUM_POOL_SIZE,
                                   CommonConstant.KEEP_ALIVE_TIME,
                                   CommonConstant.TIME_UNIT,
                                   linkedBlockingQueue,
                                    threadFactory);

    public void testThreadPool(Runnable task) {
        threadPoolExecutor.execute(task);
    }
}
